package com.alex.space.commons;

import com.alex.space.commons.cache.LRUCache1;
import com.alex.space.commons.cache.LRUCache2;
import com.alex.space.commons.cache.LRUCache3;

/**
 * @author Alex
 *         Created by Alex on 2018/1/4.
 */
public class CacheUtils {

    public static void main(String[] args) {

        LRUCache1<String, String> cache1 = new LRUCache1<>(5);

        cache1.putIfAbsent("1", "a1");
        cache1.putIfAbsent("1", "a2");
        System.out.println(cache1.toString());
        cache1.put("1", "a3");
        System.out.println(cache1.toString());
        cache1.putIfAbsent("2", "b");
        System.out.println(cache1.toString());
        cache1.putIfAbsent("3", "c");
        System.out.println(cache1.toString());
        cache1.putIfAbsent("4", "d");
        System.out.println(cache1.toString());
        cache1.putIfAbsent("5", "e");
        System.out.println(cache1.toString());
        cache1.putIfAbsent("6", "f");
        System.out.println(cache1.toString());
        cache1.putIfAbsent("7", "g");
        System.out.println(cache1.toString());
        cache1.putIfAbsent("8", "h");
        System.out.println(cache1.toString());

        System.out.println("==================");

        LRUCache2<String, String> cache2 = new LRUCache2<>(5);
        cache2.put("1", "a");
        System.out.println(cache2.toString());
        cache2.put("2", "b");
        System.out.println(cache2.toString());
        cache2.put("3", "c");
        System.out.println(cache2.toString());
        cache2.put("4", "d");
        System.out.println(cache2.toString());
        cache2.put("5", "e");
        System.out.println(cache2.toString());
        cache2.put("6", "f");
        System.out.println(cache2.toString());
        cache2.put("7", "g");
        System.out.println(cache2.toString());
        cache2.put("8", "h");
        System.out.println(cache2.toString());

        System.out.println("==================");

        LRUCache3<String, String> cache3 = new LRUCache3<>(5);
        cache3.put("1", "a");
        System.out.println(cache3.toString());
        cache3.put("2", "b");
        System.out.println(cache3.toString());
        cache3.put("3", "c");
        System.out.println(cache3.toString());
        cache3.put("4", "d");
        System.out.println(cache3.toString());
        cache3.put("5", "e");
        System.out.println(cache3.toString());
        cache3.put("6", "f");
        System.out.println(cache3.toString());
        cache3.put("7", "g");
        System.out.println(cache3.toString());
        cache3.put("8", "h");
        System.out.println(cache3.toString());
    }
}